<template>
  <div v-if="singerlist">
    <div class="topheader">
      <div class="img">
        <img :src="song.cover" alt="" />
      </div>
      <div class="button" @click="$router.go(-1)">
        <span class="iconfont icon-fanhui"></span>
        {{ song.name || "歌手" }}
      </div>
    </div>

    <dl class="musicList">
      <dt>
        <i class="iconfont icon-24gf-play"></i>播放全部<span
          >(共{{ singerlist.length }}首)</span
        >
      </dt>
      <dd
        v-for="(item, index) in singerlist"
        :key="item.id"
        @click="setId(index)"
      >
        <h1>{{ index + 1 }}</h1>
        <div class="info">
          <h2>{{ item.name }}</h2>
          <h3>
            <span v-for="value in item.ar" :key="value.id"
              >{{ value.name }}&nbsp;</span
            >
          </h3>
        </div>
      </dd>
    </dl>
  </div>
</template>

<script>
import { getSinglistDetail } from "../../api/singer";
import { getSongDetail } from "../../api/singer";
export default {
  data() {
    return {
      singerlist: null,
      song:null,
      allSinger:[]
    };
  },
  created() {
    let queryId = this.$route.query;
    if (!("id" in queryId)) {
      this.$router.push("/singer");
    }
    getSongDetail({id:queryId.id}).then(item=>{
      // console.log(item);
      this.song = item.data.artist;
      // console.log(this.song);
    })
    getSinglistDetail({ id: queryId.id }).then((item) => {
      // console.log(item);
      this.singerlist = item.songs;
      // console.log(this.singerlist);
      // for(let i=0;i<this.singerlist.length;i++){
      //   this.allSinger.push(this.singerlist[i].id);
      // }
      // console.log(this.allSinger);
    });
  },
  methods:{
      setId(index){
        // console.log(index);
        let id = this.singerlist[index].id
        this.$emit("get-singer-id",id);
        this.$emit("get-singer-all-id",this.$route.query.id);//传递歌单id
      }
  }
};
</script>

<style lang="less">
 .topheader{
        position: relative;
        height: 270px;
        .img{
            background-color: aqua;
            width: 100%;
            height: 270px;
            position: relative;
            img{
                position: absolute;
                top:0px;
                left:0px;
                right: 0px;
                bottom: 0px;
                margin:auto;
                width: 100%;
            }
        }
        .title{
            font-size: 18px;
            position: absolute;
            left:18px;
            bottom:18px;
            color:#fff;
        }
        .button{
            font-size: 18px;
            position: absolute;
            left:12px;
            top:12px;
            color:#fff;
        }
    }
     .musicList{
        background-color: #fff;
        width: 100%;
        border-radius: 7px;
        position: relative;
        top:-7px;
        padding-bottom:50px;
        dt{
            height: 36px;
            line-height: 36px;
            font-size: 16px;
            color:#454747;
            border-bottom: 1px solid #E3E3E3;
            span{
                font-size: 14px;
                color:#797B7A;
            }
            i{
                width: 44px;
                text-align: center;
                display: inline-block;
            }
        }
        dd{
            border-bottom: 1px solid #E3E3E3;
            height: 53px;
            display: flex;
            h1{
                flex: 0 0 44px;
                line-height: 53px;
                text-align: center;
                font-size: 16px;
                color:#6D6E6E;
            }
            .info{
                flex:1;
                h2{
                    width: 80vw;
                    font-size: 16px;
                    color:#1B1C1C;
                    margin-top: 10px;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
                h3{
                    font-size: 12px;
                    color:#929393;
                }
            }
        }
    }

</style>